<!DOCTYPE html>
<html lang="utf-8" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>失物招领后台管理系统</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}" href="/static/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" th:href="@{/css/font-awesome.min.css}" href="/static/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/css/ionicons.min.css}" href="/static/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/dist/css/AdminLTE.min.css}" href="/static/dist/css/AdminLTE.min.css">
    <link rel="stylesheet" th:href="@{/dist/css/skins/skin-blue.min.css}" href="/static/dist/css/skins/skin-blue.min.css">
    <link th:href="@{/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
    <!-- jQuery 2.2.3 -->
    <script th:src="@{/jquery/jquery-2.2.3.min.js}" src="/static/jquery/jquery-2.2.3.min.js"></script>
    <!-- Bootstrap 3.3.6 -->
    <script th:src="@{/bootstrap/js/bootstrap.min.js}" src="/static/bootstrap/js/bootstrap.min.js"></script>
    <!-- AdminLTE App -->
    <script th:src="@{/dist/js/app.min.js}" src="/static/dist/js/app.min.js"></script>
    <script th:src="@{/layer/layer.js}"></script>
    <!-- bootstrap-table 表格插件 -->
    <script th:src="@{/bootstrap-table/bootstrap-table.min.js}"></script>
    <script th:src="@{/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <!-- Main Header -->
    <header class="main-header">

        <!-- Logo -->
        <a href="/home" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"></span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg">失物招领后台管理系统</span>
        </a>

        <!-- Header Navbar -->
        <nav class="navbar navbar-static-top" role="navigation">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
            </a>
            <!-- Navbar Right Menu -->
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">
                    <!-- Messages: style can be found in dropdown.less-->
                    <!-- /.messages-menu -->
                    <!-- User Account Menu -->
                    <li class="dropdown user user-menu">
                        <!-- Menu Toggle Button -->
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <!-- The user image in the navbar-->
                            <img src="" class="user-image user_head_img" alt="User Image">
                            <!-- hidden-xs hides the username on small devices so only the image appears. -->
                            <span class="hidden-xs user_name"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <!-- Menu Footer-->
                            <li class="user-footer">
                                <div class="pull-right">
                                    <a th:href="@{/admin/logout}" class="btn btn-default btn-flat">退出系统</a>
                                </div>
                            </li>
                        </ul>
                    </li>

                </ul>
            </div>
        </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">

        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">

            <!-- Sidebar user panel (optional) -->
            <div class="user-panel">
                <div class="pull-left image">
                    <img  src="" class="img-circle  user_head_img" alt="User Image">
                </div>
                <div class="pull-left info">
                    <p class="user_name"></p>
                    <!-- Status -->
                    <a href="#"><i class="fa fa-circle text-success"></i> Online</a>
                </div>
            </div>


            <!-- Sidebar Menu -->
            <ul class="sidebar-menu">

                <!-- Optionally, you can add icons to the links -->
                <li  class="treeview">
                    <a href="#"><i class="glyphicon glyphicon-home"></i> <span>物品管理</span>
                        <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a th:href="@{/admin/goodlist}">物品处理</a></li>
                    </ul>
                </li>
                <li class="treeview">
                    <a href="#"><i class="glyphicon glyphicon-user"></i> <span>活动管理</span>
                        <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a th:href="@{/admin/activitylist}">活动查看</a></li>
                    </ul>
                </li>
                <li class="treeview" id="adminuser">
                    <a href="#"><i class="glyphicon glyphicon-user"></i> <span>管理员管理</span>
                        <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a th:href="@{/admin/adminuserlist}">人员列表</a></li>
                    </ul>
                </li>
            </ul>
            <!-- /.sidebar-menu -->
        </section>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                物品数据
            </h1>
            <ol class="breadcrumb">
                <li><a th:href="@{/admin/home}"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">物品管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <div class="box">
                <div class="box-search table-striped">
                    <table id="tb_departments">

                    </table>
                </div>
                <!-- /.box-header -->
                <!-- /.box-header -->
                <!-- /.box-body -->
            </div>
            <!-- /.box -->

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <!-- Main Footer -->
    <footer class="main-footer">
        <strong>Copyright &copy; 2018-2019 <a href="#">失物招领后台管理系统</a>.</strong> All rights reserved.
    </footer>

</div>
<script>
    $(function(){
        $.ajax({
            type:"POST",
            url:"/admin/userinfo",
            dataType:"json",
            contentType:"application/json",
            data:{},
            success:function (data) {
                $(".user_head_img").attr("src",data.adminUserAvatar);
                $(".user_name").html(data.adminUserRealname);
                if (data.adminUserRole=='管理员'){
                    $("#adminuser").css("display","none");
                }else {
                    $("#adminuser").css("display","block");
                }
            }
        });
        //1.初始化Table
        var oTable = new TableInit();
        oTable.Init();
        //2.初始化Button的点击事件
        var oButtonInit = new ButtonInit();
        oButtonInit.Init();

    });
    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#tb_departments').bootstrapTable({
                url: '/goodsList',         //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortName: "id",
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                //    queryParams: oTableInit.queryParams,//传递参数（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber:1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: false,                  //是否显示所有的列
                showRefresh: false,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                // clickToSelect: true,                //是否启用点击选中行
                // height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "id",                     //每一行的唯一标识，一般为主键列
                showToggle:false,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [ {
                    field: 'goodId',
                    title: '编号',
                    sortable: true
                }, {
                    field: 'goodsAddress',
                    title: '地址'
                }, {
                    field: 'goodsName',
                    title: '物品名称'
                }, {
                    field: 'goodsRealname',
                    title: '联系人'
                },{
                    field: 'goodsDate',
                    title: '时间'
                }, {
                    field: 'goodsType',
                    title: '类型',
                    formatter: function(e ,value, row, index){
                        var  actions = [];
                        if (value.goodsType == true){
                            actions.push('<div  type="text" >寻物启事</div>');
                        }else {
                            actions.push('<div type="text" >失物招领</div>');
                        }
                        return actions.join('');
                    }
                }, {
                    field: 'goodsStatus',
                    title: '状态',
                    formatter: function(e ,value, row, index){
                        var  actions = [];
                        if (value.goodsStatus == 1){
                            actions.push('<div  type="text" class="btn btn-primary btn-rounded btn-xs">发布</div>');
                        }else {
                            actions.push('<div type="text" class="btn btn-danger btn-rounded btn-xs">未发布</div>');
                        }
                        return actions.join('');
                    }
                }, {
                    field: 'Button',
                    title: '操作',
                    events: operateEvents,
                    formatter: Operate
                }
                    ,],
                showExport:false,              //是否显示导出按钮(此方法是自己写的目的是判断终端是电脑还是手机,电脑则返回true,手机返回falsee,手机不显示按钮)
            });
        };
        return oTableInit;
    };
    window.operateEvents = {
        "click #TableEditor": function (e ,value, row, index) {
            var json={"goodId":row.goodId};
            $.ajax({
                url: '/admin/publishgoods',
                type : "post",
                data: JSON.stringify(json),
                dataType: 'json',
                contentType:"application/json",
                success: function (data) {
                        if (data=="succ"){
                            $("#tb_departments").bootstrapTable('refresh',{url : "/goodsList"});
                            layer.msg('发布成功', {icon: 1});
                        }
                }});
        },
        "click #TableDelete": function (e ,value, row, index) {
                var json={"goodId":row.goodId};
                $.ajax({
                    url: '/admin/deletegoods',
                    type : "post",
                    data: JSON.stringify(json),
                    dataType: 'json',
                    contentType:"application/json",
                    success: function (data) {
                        if (data=="succ"){
                            $("#tb_departments").bootstrapTable('refresh',{url : "/goodsList"});
                            layer.msg('删除成功', {icon: 1});
                        }
                    }
                });
        }
    };
    function refreshTable() {
        $("#tb_departments").bootstrapTable('refresh',{url : "/goodsList"});
    }
    function Operate(e ,value, row, index){
        if (value.goodsStatus==1){
            return [
                '&nbsp<button id="TableDelete" type="button" class="btn btn-danger btn-xs"><i class="fa fa-remove"></i>&nbsp删除</button>'
            ].join("")
        }else {
            return [
                '<button id="TableEditor"  type="button" class="btn btn-success btn-xs"><i class="fa fa-edit"></i>&nbsp发布</button>',
                '&nbsp<button id="TableDelete" type="button" class="btn btn-danger btn-xs"><i class="fa fa-remove"></i>&nbsp删除</button>'
            ].join("")
        }
    }
    var ButtonInit = function () {
        var oInit = new Object();
        var postdata = {};
        oInit.Init = function () {
            //初始化页面上面的按钮事件
        };
        return oInit;
    };
</script>
</body>
</html>
